<template>
    <div class="wrapper-login">
        <div class="login">
            <div class="box">
                <img  src="../assets/logo.png"/>
            </div>
                <el-form ref="login" class="from" :rules="rules" :model="form" label-width="80px">
                <el-form-item label="用户名" prop="username">
                    <el-input v-model="form.username" ></el-input>
                </el-form-item>

               <el-form-item label="密码" prop="password">
                    <el-input type="password" v-model="form.password" ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">登录</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
            
        </div>
    </div>
</template>

<script>
import {Login} from '../api/user.js'
export default {
  data() {
    return {
      form: {
        username: "admin",
        password: "123456"
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" }
        ]
      }
    };
  },
  mounted() {
      
  },
  methods: {
       submitForm() {
        this.$refs.login.validate((valid) => {
          if (valid) {
            alert('submit!');
            Login({username:this.form.username,password:this.form.password}).then(res=>{
                console.log(res);
                console.log(res.data.data.token);
                localStorage.setItem('token',res.data.data.token)
                this.$router.push('/home')
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
  },
};
</script>

<style lang="scss" scoped>
.wrapper-login {
  width: 100%;
  height: 100%;
  background: #2b4b6b;
  position: relative;
  .login {
    width: 450px;
    height: 360px;
    background: white;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    .box {
      width: 130px;
      height: 130px;
      border: 1px solid #eee;
      border-radius: 50%;
      padding: 10px;
      box-shadow: 0 0 10px #ddd;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: #fff;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #eee;
      }
    }
    .from {
      margin-top: 100px;
      width: 400px;
    }
  }
}
</style>